# # 登录
# response = Order().order_login('user123', 'user123')
# print(response.json())
# token = response.json().get('data').get('token')
# print(token)
#
# # 搜索
# response = Order().order_search('母亲节')
# print(response.json())
# goodsId = response.json().get('data').get('list')[0].get('id')
# print(goodsId)
#
# # 添加购物车
# add_data = {
#     'goodsId': goodsId,
#     'number': 5,
#     'productId': 2
# }
# response = Order().order_add_shoppingCart(token, add_data)
# print(response.json())
#
# # 4、提交订单
# order_data = {
#     "addressId": "2",
#     "cartId": "0",
#     "couponId": "0",
#     "userCouponId": "0",
#     "grouponLinkId": 0,
#     "grouponRulesId": 0,
#     "message": ""
# }
# response = Order().order_submit(token, order_data)
# print(response.json())
import config
from api.order import Order
from common.utils import assert_common


class TestOrder:
    token=None
    goodsId=None

    def setup_class(self):
        self.order_api = Order()

    def test_login(self):
        response = Order().order_login(config.username,config.password)
        print(response.json())
        TestOrder.token = response.json().get('data').get('token')
        print(TestOrder.token)
        assert_common(response)


    def test_search(self):
        response = Order().order_search('母亲节')
        print(response.json())
        TestOrder.goodsId = response.json().get('data').get('list')[0].get('id')
        print(TestOrder.goodsId)
        assert_common(response)



    def test_add_shoppingCart(self):
        add_data = {
             'goodsId':  TestOrder.goodsId,
             'number': 5,
             'productId': 2
         }
        response = Order().order_add_shoppingCart(TestOrder.token, add_data)
        print(response.json())
        assert_common(response)




    def test_submit(self):
        order_data = {
            "addressId": "2",
            "cartId": "0",
            "couponId": "0",
            "userCouponId": "0",
            "grouponLinkId": 0,
            "grouponRulesId": 0,
            "message": ""
        }
        response = Order().order_submit(TestOrder.token, order_data)
        print(response.json())
        assert_common(response)
